﻿$(function () {
    ajaxCall('DataService.asmx/GetAdditionalStuff', false, "",
                function (msg) {
                    $('#lkContributors').attr("href", msg.d.Contributors);
                    $('#lkFacebook').attr("href", msg.d.Facebook);
                    $('#lkTwitter').attr("href", msg.d.Twitter);
                    $('#lkLinkedin').attr("href", msg.d.Linkedin);
                },
                function () {
                    alert("Error happend while reading from database");
                }
            );

    ajaxCall('DataService.asmx/GetAllSponsors', false, "",
                function (msg) {
                    for (var i in msg.d) {
                        var jsonstr = jQuery.parseJSON(msg.d[i]);
                        if (jsonstr.SponsorType == 'General Sponsors') {
                            $('#genSponsor').append('<a target="_blank" href="' + jsonstr.Link + '"><img src="GetImageForSponsor.ashx?id=' + jsonstr.ID + '" style="max-width:175px" /></a>');
                        }
                        else if (jsonstr.SponsorType == 'Platnum Sponsors') {
                            $('#platSponsor').append('<a target="_blank" href="' + jsonstr.Link + '"><img src="GetImageForSponsor.ashx?id=' + jsonstr.ID + '" style="max-width:175px"  /></a>');
                        }
                        else if (jsonstr.SponsorType == 'Gold Contributors') {
                            $('#goldSponsor').append('<a target="_blank" href="' + jsonstr.Link + '"><img src="GetImageForSponsor.ashx?id=' + jsonstr.ID + '" style="max-width:175px" /></a>');
                        }
                        else if (jsonstr.SponsorType == 'Silver Contributors') {
                            $('#silvSponsor').append('<a target="_blank" href="' + jsonstr.Link + '"><img src="GetImageForSponsor.ashx?id=' + jsonstr.ID + '" style="max-width:175px" /></a>');
                        }
                        else if (jsonstr.SponsorType == 'Bronze Contributors') {
                            $('#bronzSponsor').append('<a target="_blank" href="' + jsonstr.Link + '"><img src="GetImageForSponsor.ashx?id=' + jsonstr.ID + '" style="max-width:175px"  /></a>');
                        }
                        else if (jsonstr.SponsorType == 'Promoters') {
                            $('#promoters').append('<a target="_blank" href="' + jsonstr.Link + '"><img src="GetImageForSponsor.ashx?id=' + jsonstr.ID + '" style="max-width:175px" /></a>');
                        }
                    }
                },
                function () {
                    alert("Error happend while reading data from database");
                }
            );

    ajaxCall('../DataService.asmx/GetNotifications', false, "",
                function (msg) {
                    if (msg.d.length == 0) {
                        $('#featuredDiv').html("There are no notifications in the database");
                    } else {
                        var untill;
                        if (msg.d.length < 2) {
                            untill = msg.d.length;
                        } else {
                            untill = 2;
                        }
                        for (var i = 0; i < untill; i++) {
                            var announcements = [
                        { ID: msg.d[i].ID, Title: msg.d[i].Title, Date: JSONDate(msg.d[i].Date), Description: msg.d[i].Description.substring(0, 100) + "...", Link: msg.d[i].Link },
                    ];

                            $('#FeaturedTemplate').tmpl(announcements).appendTo('#featuredDiv');
                        }
                    }

                },
                function () {
                    alert("#Error happend while reading data from the database");
                }
            );

    ajaxCall('DataService.asmx/GetAllEvents', false, "",
                function (msg) {
                    for (var i in msg.d) {
                        if (msg.d[i].Finished == '1') {
                            $('#subnavHistory').append("<li><a href='PreviousEvents.aspx?id=" + msg.d[i].EventID + "'>" + msg.d[i].EventName + "</a></li>");
                        }

                    }
                },
                function () {
                    alert("Error happend while reading events from database");
                }
            );
});